﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kinect.GPart
{
    class GFuck
    {
        public static bool FuckPoint(byte[] bits, int width, int height, int offset, int x, int y, byte r, byte g, byte b)
        {
            if (x < 0 || x >= width) x = -1;
            if (y < 0 || y >= height) y = -1;

            if (x == -1 || y == -1) return false;
            for (int d = -offset; d <= offset; d++)
            {
                int i = x + d, j = y + d;
                if (i < 0 || i >= width) continue;
                if (j < 0 || j >= height) continue;
                setColor(bits, width, i, j, r, g, b);
            }
            for (int d = -offset; d <= offset; d++)
            {
                int i = x + d, j = y - d;
                if (i < 0 || i >= width) continue;
                if (j < 0 || j >= height) continue;
                setColor(bits, width, i, j, r, g, b);
            }
            return true;
        }

        public static bool FuckBorder(byte[] bits, int width, int height, int offset, int x, int y)
        {
            if (x < 0 || x >= width) x = -1;
            if (y < 0 || y >= height) y = -1;

            if (x == -1 || y == -1) return false;

            int j1 = Math.Max(y - offset, 0), j2 = Math.Min(y + offset, height - 1);
            int i1 = Math.Max(x - offset, 0), i2 = Math.Min(x + offset, width - 1);
            for (int i = i1; i <= i2; i++)
            {
                setColor(bits, width, i, j1, 255, 0, 0);
                setColor(bits, width, i, j2, 255, 0, 0);
            }
            for (int j = j1; j <= j2; j++)
            {
                setColor(bits, width, i1, j, 255, 0, 0);
                setColor(bits, width, i2, j, 255, 0, 0);
            }
            return true;
        }

        public static void setColor(byte[] bits, int width, int x, int y, byte red, byte green, byte blue)
        {
            bits[(x + y * width) * 4 + GParam.RedIndex] = red;
            bits[(x + y * width) * 4 + GParam.GreenIndex] = green;
            bits[(x + y * width) * 4 + GParam.BlueIndex] = blue;
        }

    }
}
